﻿using DmxTestTool.Model;
using DmxTestTool.UI.template;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace DmxTestTool.UI
{
    /// <summary>
    /// DMXViewUIControl.xaml 的交互逻辑
    /// </summary>
    public partial class DMXViewUIControl : UserControl
    {
        public long DMXID { set; get; }
        public static readonly DependencyProperty DmxViewItemSourceProperty;
        static DMXViewUIControl()
        {
            DmxViewItemSourceProperty = DependencyProperty.Register("DmxViewItemSource", typeof(List<DmxViewItemModel>), typeof(DMXViewUIControl),
                new PropertyMetadata(new List<DmxViewItemModel>() { new DmxViewItemModel {  Index=1} }, DmxViewItemSourceChanged
                ));
        }

        private static void DmxViewItemSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DMXViewUIControl ctr = d as DMXViewUIControl;
            if (ctr == null)
                return;
           var source = e.NewValue as List<DmxViewItemModel>;
            ctr.wp.Children.Clear();
            for (int i = 0; i < source.Count; i++)
            {
                DmxViewItemModel model = source[i];
                DmxViewItemTemplate template = new DmxViewItemTemplate(model);
                template.Width = 35;
                template.Height = 190;
                template.Margin = new Thickness(3);
                ctr.wp.Children.Add(template);
            }
        }
        public List<DmxViewItemModel> DmxViewItemSource
        {
            set => SetValue(DmxViewItemSourceProperty, value);
            get => (List<DmxViewItemModel>)GetValue(DmxViewItemSourceProperty);
        }
      

        public DMXViewUIControl()
        {
            InitializeComponent();
        }
        private bool isLoad = false;
        private void DMXViewUIControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (!isLoad)
            {
                //this.wp.Children.Clear();
                //for (int i = 0; i < count; i++)
                //{
                //    DmxViewItemModel model = new DmxViewItemModel { Index = i + 1, Value = 0 };
                //    DmxViewItemTemplate template = new DmxViewItemTemplate(model);
                //    wp.Children.Add(template);
                //}
                isLoad = true;
            }
         
        }
    }
}
